/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package utn.frsf.cidisi.upcolbpip.interactionprotocols.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.impl.EObjectImpl;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.BusinessDocument;
import utn.frsf.cidisi.upcolbpip.b2bcollaborations.SpeechAct;

import utn.frsf.cidisi.upcolbpip.interactionprotocols.BusinessMessage;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.Condition;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionPath;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionprotocolsPackage;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.Lifeline;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.TimeExpresion;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Business Message</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getTimeToReceiptAcknowledgement <em>Time To Receipt Acknowledgement</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getTimeToReadAcknowledgement <em>Time To Read Acknowledgement</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getSender <em>Sender</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getReceiver <em>Receiver</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getGuard <em>Guard</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getIntention <em>Intention</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getInformation <em>Information</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.BusinessMessageImpl#getBmInteractionPath <em>Bm Interaction Path</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BusinessMessageImpl extends InteractionProtocolElementImpl implements BusinessMessage {
	/**
	 * The default value of the '{@link #getTimeToReceiptAcknowledgement() <em>Time To Receipt Acknowledgement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeToReceiptAcknowledgement()
	 * @generated
	 * @ordered
	 */
	protected static final String TIME_TO_RECEIPT_ACKNOWLEDGEMENT_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getTimeToReceiptAcknowledgement() <em>Time To Receipt Acknowledgement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeToReceiptAcknowledgement()
	 * @generated
	 * @ordered
	 */
	protected String timeToReceiptAcknowledgement = TIME_TO_RECEIPT_ACKNOWLEDGEMENT_EDEFAULT;

	/**
	 * The default value of the '{@link #getTimeToReadAcknowledgement() <em>Time To Read Acknowledgement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeToReadAcknowledgement()
	 * @generated
	 * @ordered
	 */
	protected static final String TIME_TO_READ_ACKNOWLEDGEMENT_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getTimeToReadAcknowledgement() <em>Time To Read Acknowledgement</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTimeToReadAcknowledgement()
	 * @generated
	 * @ordered
	 */
	protected String timeToReadAcknowledgement = TIME_TO_READ_ACKNOWLEDGEMENT_EDEFAULT;

	/**
	 * The cached value of the '{@link #getSender() <em>Sender</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSender()
	 * @generated
	 * @ordered
	 */
	protected Lifeline sender;

	/**
	 * The cached value of the '{@link #getReceiver() <em>Receiver</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReceiver()
	 * @generated
	 * @ordered
	 */
	protected Lifeline receiver;

	/**
	 * The cached value of the '{@link #getGuard() <em>Guard</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGuard()
	 * @generated
	 * @ordered
	 */
	protected Condition guard;

	/**
	 * The default value of the '{@link #getIntention() <em>Intention</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIntention()
	 * @generated
	 * @ordered
	 */
	protected static final SpeechAct INTENTION_EDEFAULT = SpeechAct.REQUEST;

	/**
	 * The cached value of the '{@link #getIntention() <em>Intention</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIntention()
	 * @generated
	 * @ordered
	 */
	protected SpeechAct intention = INTENTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getInformation() <em>Information</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInformation()
	 * @generated
	 * @ordered
	 */
	protected BusinessDocument information;

	/**
	 * The cached value of the '{@link #getBmInteractionPath() <em>Bm Interaction Path</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBmInteractionPath()
	 * @generated
	 * @ordered
	 */
	protected InteractionPath bmInteractionPath;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BusinessMessageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InteractionprotocolsPackage.Literals.BUSINESS_MESSAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getTimeToReceiptAcknowledgement() {
		return timeToReceiptAcknowledgement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTimeToReceiptAcknowledgement(String newTimeToReceiptAcknowledgement) {
		String oldTimeToReceiptAcknowledgement = timeToReceiptAcknowledgement;
		timeToReceiptAcknowledgement = newTimeToReceiptAcknowledgement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_RECEIPT_ACKNOWLEDGEMENT, oldTimeToReceiptAcknowledgement, timeToReceiptAcknowledgement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getTimeToReadAcknowledgement() {
		return timeToReadAcknowledgement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTimeToReadAcknowledgement(String newTimeToReadAcknowledgement) {
		String oldTimeToReadAcknowledgement = timeToReadAcknowledgement;
		timeToReadAcknowledgement = newTimeToReadAcknowledgement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_READ_ACKNOWLEDGEMENT, oldTimeToReadAcknowledgement, timeToReadAcknowledgement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline getSender() {
		if (sender != null && sender.eIsProxy()) {
			InternalEObject oldSender = (InternalEObject)sender;
			sender = (Lifeline)eResolveProxy(oldSender);
			if (sender != oldSender) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER, oldSender, sender));
			}
		}
		return sender;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline basicGetSender() {
		return sender;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSender(Lifeline newSender) {
		Lifeline oldSender = sender;
		sender = newSender;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER, oldSender, sender));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline getReceiver() {
		if (receiver != null && receiver.eIsProxy()) {
			InternalEObject oldReceiver = (InternalEObject)receiver;
			receiver = (Lifeline)eResolveProxy(oldReceiver);
			if (receiver != oldReceiver) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER, oldReceiver, receiver));
			}
		}
		return receiver;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline basicGetReceiver() {
		return receiver;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReceiver(Lifeline newReceiver) {
		Lifeline oldReceiver = receiver;
		receiver = newReceiver;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER, oldReceiver, receiver));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Condition getGuard() {
		return guard;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetGuard(Condition newGuard, NotificationChain msgs) {
		Condition oldGuard = guard;
		guard = newGuard;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD, oldGuard, newGuard);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGuard(Condition newGuard) {
		if (newGuard != guard) {
			NotificationChain msgs = null;
			if (guard != null)
				msgs = ((InternalEObject)guard).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD, null, msgs);
			if (newGuard != null)
				msgs = ((InternalEObject)newGuard).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD, null, msgs);
			msgs = basicSetGuard(newGuard, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD, newGuard, newGuard));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SpeechAct getIntention() {
		return intention;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIntention(SpeechAct newIntention) {
		SpeechAct oldIntention = intention;
		intention = newIntention == null ? INTENTION_EDEFAULT : newIntention;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__INTENTION, oldIntention, intention));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BusinessDocument getInformation() {
		if (information != null && information.eIsProxy()) {
			InternalEObject oldInformation = (InternalEObject)information;
			information = (BusinessDocument)eResolveProxy(oldInformation);
			if (information != oldInformation) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION, oldInformation, information));
			}
		}
		return information;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BusinessDocument basicGetInformation() {
		return information;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInformation(BusinessDocument newInformation) {
		BusinessDocument oldInformation = information;
		information = newInformation;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION, oldInformation, information));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InteractionPath getBmInteractionPath() {
		if (bmInteractionPath != null && bmInteractionPath.eIsProxy()) {
			InternalEObject oldBmInteractionPath = (InternalEObject)bmInteractionPath;
			bmInteractionPath = (InteractionPath)eResolveProxy(oldBmInteractionPath);
			if (bmInteractionPath != oldBmInteractionPath) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH, oldBmInteractionPath, bmInteractionPath));
			}
		}
		return bmInteractionPath;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public InteractionPath basicGetBmInteractionPath() {
		return bmInteractionPath;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBmInteractionPath(InteractionPath newBmInteractionPath) {
		InteractionPath oldBmInteractionPath = bmInteractionPath;
		bmInteractionPath = newBmInteractionPath;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH, oldBmInteractionPath, bmInteractionPath));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD:
				return basicSetGuard(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_RECEIPT_ACKNOWLEDGEMENT:
				return getTimeToReceiptAcknowledgement();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_READ_ACKNOWLEDGEMENT:
				return getTimeToReadAcknowledgement();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER:
				if (resolve) return getSender();
				return basicGetSender();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER:
				if (resolve) return getReceiver();
				return basicGetReceiver();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD:
				return getGuard();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INTENTION:
				return getIntention();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION:
				if (resolve) return getInformation();
				return basicGetInformation();
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH:
				if (resolve) return getBmInteractionPath();
				return basicGetBmInteractionPath();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_RECEIPT_ACKNOWLEDGEMENT:
				setTimeToReceiptAcknowledgement((String)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_READ_ACKNOWLEDGEMENT:
				setTimeToReadAcknowledgement((String)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER:
				setSender((Lifeline)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER:
				setReceiver((Lifeline)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD:
				setGuard((Condition)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INTENTION:
				setIntention((SpeechAct)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION:
				setInformation((BusinessDocument)newValue);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH:
				setBmInteractionPath((InteractionPath)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_RECEIPT_ACKNOWLEDGEMENT:
				setTimeToReceiptAcknowledgement(TIME_TO_RECEIPT_ACKNOWLEDGEMENT_EDEFAULT);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_READ_ACKNOWLEDGEMENT:
				setTimeToReadAcknowledgement(TIME_TO_READ_ACKNOWLEDGEMENT_EDEFAULT);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER:
				setSender((Lifeline)null);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER:
				setReceiver((Lifeline)null);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD:
				setGuard((Condition)null);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INTENTION:
				setIntention(INTENTION_EDEFAULT);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION:
				setInformation((BusinessDocument)null);
				return;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH:
				setBmInteractionPath((InteractionPath)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_RECEIPT_ACKNOWLEDGEMENT:
				return TIME_TO_RECEIPT_ACKNOWLEDGEMENT_EDEFAULT == null ? timeToReceiptAcknowledgement != null : !TIME_TO_RECEIPT_ACKNOWLEDGEMENT_EDEFAULT.equals(timeToReceiptAcknowledgement);
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__TIME_TO_READ_ACKNOWLEDGEMENT:
				return TIME_TO_READ_ACKNOWLEDGEMENT_EDEFAULT == null ? timeToReadAcknowledgement != null : !TIME_TO_READ_ACKNOWLEDGEMENT_EDEFAULT.equals(timeToReadAcknowledgement);
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__SENDER:
				return sender != null;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__RECEIVER:
				return receiver != null;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__GUARD:
				return guard != null;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INTENTION:
				return intention != INTENTION_EDEFAULT;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__INFORMATION:
				return information != null;
			case InteractionprotocolsPackage.BUSINESS_MESSAGE__BM_INTERACTION_PATH:
				return bmInteractionPath != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (timeToReceiptAcknowledgement: ");
		result.append(timeToReceiptAcknowledgement);
		result.append(", timeToReadAcknowledgement: ");
		result.append(timeToReadAcknowledgement);
		result.append(", intention: ");
		result.append(intention);
		result.append(')');
		return result.toString();
	}

} //BusinessMessageImpl
